package org.hit.burkun.network.tester;

import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;

import org.hit.burkun.file.FileHelper;
import org.hit.burkun.network.EdgeInfo;
import org.hit.burkun.network.SerializableGraph;
import org.hit.burkun.network.models.StaticMethods;
import org.hit.burkun.swalk.SeribaleGraphAdpater;

public class BioGraphTester {

	private static HashMap<String, HashSet<EdgeInfo>> validTrue = ValidData.readTestFalseValidObj();
	private static HashMap<String, HashSet<EdgeInfo>> validFalse = ValidData.readTestFalseValidObj();

	
	public static void main(String[] args) {
//		weight();
//		noWeight();
//		
	}
	
	private static void writeToFile(String fileName, LinkedList<String> lines){
		FileHelper.writeFile(fileName, lines);
	}
	
	private static void noWeight(double salpha){
		SerializableGraph sg = StaticMethods.loadGraphNoDir();
		HashSet<String> umls = ValidData.getValidUmls();
		double eps = 1e-3;
		double galpha = 0;
		double[] uweip = new double[]{1};
		//double[] weip = new double[]{1};
		String fileName = "data/ranking/noweight";
		for(String cui : umls){
			//获取所的，不适用权值的ranking值
			LinkedList<String> allPr = SeribaleGraphAdpater.getBioGraphRankingByUmls(cui, sg, eps, galpha, salpha, uweip, false);
			String name = fileName +"-"+ cui +"-"+ salpha +".txt";
			writeToFile(name, allPr);
		}
	}
	
	private static void weight(double salpha){
		SerializableGraph sg = StaticMethods.loadGraphNoDir();
		HashSet<String> umls = ValidData.getValidUmls();
		double eps = 1e-3;
		double galpha = 0;
		//double[] uweip = new double[]{1};
		double[] weip = new double[9];
		for(int i=0 ; i< 9; i++){
			weip[i] = 1;
		}
		String fileName = "data/ranking/weight";
		for(String cui : umls){
			//获取所有的使用权值的ranking值
			LinkedList<String> allPr = SeribaleGraphAdpater.getBioGraphRankingByUmls(cui, sg, eps, galpha, salpha, weip, true);
			String name = fileName +"-"+ cui +"-"+ salpha +".txt";
			writeToFile(name, allPr);
		}
	}
	//使用优化后的ranking值
	private static void superWeight(){
		SerializableGraph sg = StaticMethods.loadGraphNoDir();
		HashSet<String> umls = ValidData.getValidUmls();
		double eps = 1e-3;
		double galpha = 0;
		double salpha = 0.2;
		//double[] uweip = new double[]{1};
		double[] weip = new double[9];
		for(int i=0 ; i< 9; i++){
			weip[i] = 1;
		}
		String fileName = "data/ranking/superweight";
		for(String cui : umls){
			LinkedList<String> allPr = SeribaleGraphAdpater.getBioGraphRankingByUmls(cui, sg, eps, galpha, salpha, weip, true);
			String name = fileName +"-"+ cui +"-"+ salpha +".txt";
			writeToFile(name, allPr);
		}
	}
	
	
//	private static void filterValidGenes(LinkedList<String> allPr, String curUmls){
//		LinkedList<String> filterPr = new LinkedList<>();
//		HashSet<EdgeInfo> edgeTrue = validTrue.get(curUmls);
//		HashSet<EdgeInfo> edgeFalse = validTrue.get(curUmls);
//		for(String line : allPr){
//			String[] args = line.split(":");
//			for(EdgeInfo e : edgeTrue){
//				if(e.toString().equals(args[1])){
//					filterPr.add(line);
//					break;
//				}
//			}
//			for(EdgeInfo e : edgeFalse){
//				if(e.toString().equals(args[1])){
//					filterPr.add(line);
//					break;
//				}
//			}
//		}
//	}
	
}

